package org.jetnuke.modules.admin.content;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.PagesCategories;
import org.jetnuke.util.JetUtil;

public class CreateCategory implements IAction {
	String name, description;

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		if (ai == null || (!ai.IsSuperUser() && !ai.isAdminContent()))
			return null;//Error;

		PagesCategories cat = new PagesCategories();
		cat.setTITLE(name);
		cat.setDESCRIPTION(description);
		DataAccessDriver.getInst().newPagesCatDAO().addNew(cat);
		//cat.save();
		JetUtil.redirect(vc,response,request.getContextPath()+"/do/admin/content_manager");
		return null;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setName(String name) {
		this.name = name;
	}
}
